<template>
  <div>
    <zh-form ref="fileInfoRef" :md="8" :lg="8" :xl="8"  :model="fileInfo"  labelWidth="200">

      <zh-form-input prop="showId" label="文件显示id"  v-model="fileInfo.showId"
                     disabled></zh-form-input>
      <zh-form-input prop="classTitle" label="文件分类"  v-model="fileInfo.classTitle"
                     disabled></zh-form-input>
      <zh-form-input prop="fileName" label="文件名称"  v-model="fileInfo.fileName"
                     :disabled="state.disabledCollectData"></zh-form-input>
      <zh-form-input prop="fileSuffix" label="文件后缀"  v-model="fileInfo.fileSuffix"
                     disabled></zh-form-input>
      <zh-form-input prop="filePath" label="文件存放路径"  v-model="fileInfo.filePath"
                     disabled></zh-form-input>
      <zh-form-input prop="fileSize" label="文件大小"  v-model="fileInfo.fileSize"
                     disabled></zh-form-input>
      <zh-form-input prop="orgId" label="公司id"  v-model="fileInfo.orgId"
                     disabled></zh-form-input>
      <zh-form-select prop="encryptionFlag" label="是否加密"  v-model="fileInfo.encryptionFlag"
                      :options="state.dictData.flag"
                     disabled></zh-form-select>
      <zh-form-input prop="filePassowrd" label="文件加密密码"  v-model="fileInfo.filePassowrd"
                     disabled></zh-form-input>
      <zh-form-input prop="zipPassword" label="压缩包解压密码"  v-model="fileInfo.zipPassword"
                     disabled></zh-form-input>
      <zh-form-select prop="fielderFlag" label="是否归档"  v-model="fileInfo.fielderFlag"
                      :options="state.dictData.flag"
                      disabled></zh-form-select>
      <zh-form-input prop="upAppName" label="上传应用"  v-model="fileInfo.upAppName"
                     disabled></zh-form-input>
      <zh-form-input prop="uploader" label="上传人"  v-model="fileInfo.uploader"
                     disabled></zh-form-input>
      <zh-form-input prop="upTime" label="上传时间"  v-model="fileInfo.upTime"
                     disabled></zh-form-input>
      <zh-form-input prop="fileder" label="归档人"  v-model="fileInfo.fileder"
                     disabled></zh-form-input>
      <zh-form-input prop="filederTime" label="归档时间"  v-model="fileInfo.filederTime"
                     disabled></zh-form-input>
      <zh-form-input type="textarea" prop="remarks" label="备注"  v-model="fileInfo.remarks"
                     disabled></zh-form-input>
      <zh-form-select
          :disabled="props.disabled"
          prop="secrecyLevel"
          label="保密级别"
          :options="state.secrecyLevelDict"
          v-model="fileInfo.secrecyLevel"
      ></zh-form-select>
      <zh-form-input  prop="fileClassPath" label="文件存放路径"  v-model="fileInfo.fileClassPath"
                     disabled></zh-form-input>
      <zh-form-input  prop="envName" label="环境名称"  v-model="fileInfo.envName"
                      disabled></zh-form-input>
      <zh-form-input  prop="fileServiceType" label="文件服务器类型"  v-model="fileInfo.fileServiceType"
                      disabled></zh-form-input>
      <zh-form-input  prop="fileServiceIp" label="文件服务ip"  v-model="fileInfo.fileServiceIp"
                      disabled></zh-form-input>
      <zh-form-input  prop="fileServicePort" label="端口"  v-model="fileInfo.fileServicePort"
                      disabled></zh-form-input>
      <zh-form-input  prop="storageGroup" label="存储服务器组"  v-model="fileInfo.storageGroup"
                      disabled></zh-form-input>
      <zh-form-input  prop="fileBasePath" label="文件存放基础路径"  v-model="fileInfo.fileBasePath"
                      disabled></zh-form-input>
      <zh-form-input  prop="webPort" label="静态文件服务访问端口"  v-model="fileInfo.webPort"
                      disabled></zh-form-input>
      <zh-form-input  prop="webBasePath" label="静态文件访问基础路径"  v-model="fileInfo.webBasePath"
                      disabled></zh-form-input>
      <zh-form-upload
          v-if="state.fileType=='picture'"
          disabled
          prop="file"
          label="文件"
          ref="uploadRef"
          type="picture"
          :limit="1"
          drag
          multiple
          v-model="fileInfo.showId"
      />
      <zh-form-upload
          v-if="state.fileType=='file'"
          disabled
          prop="file"
          label="文件"
          ref="uploadRef"
          type="file"
          :limit="1"
          drag
          multiple
          v-model="fileInfo.showId"
      />
      <zh-form-upload
          v-if="state.fileType=='video'"
          disabled
          prop="file"
          label="文件"
          ref="uploadRef"
          type="video"
          :limit="1"
          drag
          multiple
          v-model="fileInfo.showId"
      />
    </zh-form>
  </div>
</template>
<script lang="ts" setup name="fileInfo">

const fileInfoRef=ref();
const fileInfo = ref<any>({
});

const props = defineProps({
  disabled: {
    type: Boolean,
    default: true,
  },
  
});

const state = reactive({
  dictData:[],
  secrecyLevelDict:[
    {
      dictKey:'1',
      dictValue:'一级'
    },
    {
      dictKey:'2',
      dictValue:'二级'
    },
    {
      dictKey:'3',
      dictValue:'三级'
    },
  ],
  fileType:'picture',
  //归档后文件名允许修改
  disabledCollectData: true,
  
})

//---------------------初始化---------------------
const params = {
  dictFields: 'flag',
};
$api.common.getBatchDict.post(params).then((res) => {
  state.dictData = res.result;
});


function setInitData(info) {
  fileInfoRef.value?.resetFields();
  if (info) {
    //根据id获取详细信息
    $api.common.fileSend.post('fileManager0002', {fileId:info.fileId}).then((res) => {
      fileInfo.value = res.result;
      if(isAssetTypeAnImage(fileInfo.value.fileSuffix)){
        state.fileType='picture'
      }else if(isAssetTypeAVideo(fileInfo.value.fileSuffix)){
        state.fileType='video'
      }else{
        state.fileType='file'
      }
    }).catch(() => {});
  }
}

//filecollectData归集文件管理模块专用
function setInitCollectData(info) {
  fileInfoRef.value?.resetFields();
  if (info) {
    //根据id获取详细信息
    $api.common.fileSend.post('fileCollectData0002', {collectDataId:info.collectDataId}).then((res) => {
      fileInfo.value = res.result;
      if(isAssetTypeAnImage(fileInfo.value.fileSuffix)){
        state.fileType='picture'
      }else if(isAssetTypeAVideo(fileInfo.value.fileSuffix)){
        state.fileType='video'
      }else{
        state.fileType='file'
      }
    }).catch(() => {});
    state.disabledCollectData=false;
  }
}

//判断是否为图片
function isAssetTypeAnImage(ext) {
  return [
    'png', 'jpg', 'jpeg', 'bmp', 'gif', 'webp', 'psd', 'svg', 'tiff'].
  indexOf(ext.toLowerCase()) !== -1;
}
//判断是否为视频
function isAssetTypeAVideo(ext) {
  return [
    'avi', 'wmv', 'mpg', 'mpeg', 'mov', 'rm', 'swf', 'flv', 'mp4'].
  indexOf(ext.toLowerCase()) !== -1;
}

//------------设置给父组件调用的数据/方法(组件)-----------
defineExpose({setInitData,fileInfo,setInitCollectData});
</script>